define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'general/heyinfo/index',
                    add_url: 'general/heyinfo/add',
                    edit_url: 'general/heyinfo/edit',
                    del_url: 'general/heyinfo/del',
                    multi_url: 'general/heyinfo/multi',
                    table: 'heyinfo',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'admin_id', title: __('ID')},  
                        {field: 'shop_url', title: __('Shop_url'), formatter: Table.api.formatter.url},
                        // {field: 'shop_hash', title: __('Shop_hash')},
                        {field: 'comp_name', title: __('Comp_name')},
                        // {field: 'comp_phone', title: __('Comp_phone')},
                        // {field: 'comp_email', title: __('Comp_email')},
                        // {field: 'ent_code', title: __('Ent_code')},
                        // {field: 'ent_name', title: __('Ent_name')},
                        {field: 'goods_update', title: __('Goods_update'), formatter: Table.api.formatter.datetime},
                        {field: 'order_update', title: __('Order_update'), formatter: Table.api.formatter.datetime},
                        {field: 'express_update', title: __('Express_update'), formatter: Table.api.formatter.datetime},
                        {field: 'trans_switch', title: __('Trans_switch'), searchList: {"0":__('Trans_switch 0'),"1":__('Trans_switch 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'update_switch', title: __('Update_switch'), searchList: {"0":__('Update_switch 0'),"1":__('Update_switch 1')}, formatter: Table.api.formatter.toggle},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'admin.nickname', title: __('Admin.nickname')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons:[
                            {
                                name: 'ajax',
                                text: '',
                                title: __('同步商品'),
                                classname: 'btn btn-xs btn-default btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                url: '/api/hey/trans_goods?admin_id={admin_id}',
                                confirm: '确认发送',
                                extend: ' data-toggle="tooltip"',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },{
                                name: 'ajax',
                                text: '',
                                title: __('同步订单'),
                                classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                url: '/api/hey/trans_order?admin_id={admin_id}',
                                confirm: '确认发送',
                                extend: ' data-toggle="tooltip"',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                            
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});